package com.xiaxiang.xiaxwan.ar.data;

import android.os.Parcel;
import android.os.Parcelable;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by Administrator on 2017-10-30.
 */

public class XXARMaterialVideoData extends JSONObject implements Parcelable {
    public final static String MATERIAL_ID_KEY = "materialId";
    public final static String MATERIAL_URL_KEY = "materialUrl";
    public final static String USER_NAME_KEY = "userName";
    public final static String NAME_KEY = "name";
    public final static String MATERIAL_NAME_KEY = "materialName";
    public final static String VIDEO_URL_KEY ="videoUrl";
    public final static String MEED_VIDEO_KEY = "needVideo";
    public final static String AR_MODE_KEY = "arMode";
    private final static String PIC_FILE_NAME_KEY = "picFileName";
    private final static String HEAD_PHOTO = "";
    //public static String THUMBNAIL_KEY = "thumbnail";
 //   public final static String TARGET_NAME_KEY = "targetName";
    public boolean mNeedVideoPath = false;
    public byte mNeedMediaStyle = 0;//0代表不需要videoPath,1需要
    public int mArMode = 1;
    public int mVideoId = -1;
    public String mUserName = "";
    public String mName = "";
    public String mMaterialId = "";
    public String mMaterialUrl ="";
    public String mVideoPath = null;
    public String mMaterialPathName ="";
    public String mPicFilePath = "";
    public String mThumbnailUrl = "";
    public String mHeadPhoto = "";
    public XXARMaterialVideoData(String jsonStr) throws JSONException {
        super(jsonStr);
        initJSONData(this);
    }

    public XXARMaterialVideoData(JSONObject jsonObject){
        initJSONData(jsonObject);
    }

    public XXARMaterialVideoData(){

    }

    protected XXARMaterialVideoData(Parcel in) {
        mNeedMediaStyle = in.readByte();
        mArMode = in.readInt();
        mVideoId = in.readInt();
        mVideoPath = in.readString();
        mMaterialId =  in.readString();
        mMaterialUrl =   in.readString();
        mUserName =  in.readString();
        mName =   in.readString();
        mMaterialPathName = in.readString();
        mThumbnailUrl = in.readString();
        mPicFilePath = in.readString();
        mHeadPhoto = in.readString();
        if(mNeedMediaStyle == 1){
            mNeedVideoPath = true;
        }else{
            mNeedVideoPath = false;
        }
    }

    public void setNeedVideoPath(boolean is){
        mNeedVideoPath = is;
        if(is){
            mNeedMediaStyle = 1;
        }else{
            mNeedMediaStyle = 0;
        }
    }
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeByte(mNeedMediaStyle);
        dest.writeInt(mArMode);
        dest.writeInt(mVideoId);
        dest.writeString(mVideoPath);
        dest.writeString(mMaterialId);
        dest.writeString(mMaterialUrl);
        dest.writeString(mUserName);
        dest.writeString(mName);
        dest.writeString(mMaterialPathName);
        dest.writeString(mThumbnailUrl);
        dest.writeString(mPicFilePath);
        dest.writeString(mHeadPhoto);
    }

    private void initJSONData(JSONObject jsonObject){
        try {
            mVideoPath = jsonObject.getString(VIDEO_URL_KEY);
            mMaterialId =  jsonObject.getString(MATERIAL_ID_KEY);
            mMaterialUrl =  jsonObject.getString(MATERIAL_URL_KEY);
            mUserName = jsonObject.getString(USER_NAME_KEY);
            mName =  jsonObject.getString(NAME_KEY);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        if(mVideoPath == null){
            mVideoPath = "";
        }
    }
    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<XXARMaterialVideoData> CREATOR = new Creator<XXARMaterialVideoData>() {
        @Override
        public XXARMaterialVideoData createFromParcel(Parcel in) {
            return new XXARMaterialVideoData(in);
        }

        @Override
        public XXARMaterialVideoData[] newArray(int size) {
            return new XXARMaterialVideoData[size];
        }
    };
}
